//
//  FontNameSelectView.m
//  BigJoy
//
//  Created by Rowling on 2017/6/26.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "FontNameSelectView.h"

@interface FontNameSelectView()<UIPickerViewDelegate,UIPickerViewDataSource>

@property(nonatomic,strong)UIPickerView * pickView;
@property (nonatomic,strong) NSArray *fontNameArray;

@end

@implementation FontNameSelectView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}

-(void)setUI {
    self.fontNameArray = [UIFont familyNames];
    self.backgroundColor = [UIColor whiteColor];
    self.pickView = [[UIPickerView alloc]initWithFrame:self.bounds];
    [self addSubview:self.pickView];
    self.pickView.delegate = self;
    self.pickView.dataSource = self;
    self.pickView.backgroundColor = [UIColor whiteColor];
    self.pickView.showsSelectionIndicator = YES;
    [self.pickView selectRow:0 inComponent:0 animated:YES];
    [self changeSpearatorLineColor];
}

#pragma mark - 改变分割线的颜色
- (void)changeSpearatorLineColor
{
    for(UIView *speartorView in self.pickView.subviews)
    {
        if (speartorView.frame.size.height < 1)//取出分割线view
        {
            speartorView.backgroundColor =  [UIColor blackColor];//隐藏分割线
        }
    }
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return self.fontNameArray.count;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return self.fontNameArray[row];
}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    return 40;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (self.fontSelectBlock) {
        self.fontSelectBlock(self.fontNameArray[row]);
    }
}

@end
